//定义数据 home 的数据
import _ from "lodash"
const initState = {
    visible: false,
    backfill: null,  //数据回显
    data: [
        { name: '张三', age: 10, address: '五湖四海' },
        { name: '李四', age: 31, address: '五湖四海' },
        { name: '王五', age: 21, address: '五湖四海' },
    ],
}


//定义修改方法
const reducer = (state = initState, action) => {
    console.log("查询");
    let tmp = _.cloneDeep(state)

    switch (action.type) {
        case 'Switch_Visible':
            tmp.backfill = tmp.data[action.payload.index]
            console.log(tmp.data[action.payload.index], '开关');
            tmp.visible = action.payload
            return tmp
        case 'del_modaldata':
            console.log(action.payload, '删除');
            console.log(tmp.data, 'tmp');
            tmp.data.splice(action.payload, 1)
            return tmp
        case 'up_modaldata':
            console.log(tmp.data, '上移动');
            let index = action.payload
            let con = tmp.data[index];
            tmp.data[index] = tmp.data[index - 1];
            tmp.data[index - 1] = con;
            return tmp
        case 'down_modaldata':
            console.log(tmp.data, '下移动');
            let i = action.payload
            let icon = tmp.data[i];
            tmp.data[i] = tmp.data[i + 1];
            tmp.data[i + 1] = icon;
            return tmp
        case 'pushdata_modaldata':
            console.log(action.payload[1], '添加或更新数据');
            if (action.payload[1] === 'ADD') {
                tmp.data.push(action.payload[0])
            } else if (action.payload[1] === 'UPDATA') {
                let [ps, str, index] = action.payload
                tmp.data[index] = ps
                tmp.backfill = ps
            }
            return tmp
        default:
            break;
    }
    return tmp
}
export default reducer